package service

import (
	"choujiang/common/models"
	"choujiang/common/utils"
	"choujiang/common/db"
	"choujiang/common/consts"
)

/**
 通过输入渠道码绑定用户渠道
 */
func UserBindChannel(user *model.User, channel string) *utils.ErrorType {
	count, _ := db.MysqlEngine.SQL("select count(*) from channel where name = ?", channel).Count()
	if count == 0 {
		return consts.ErrChannelNotExist
	}
	user.FromChannel = channel
	user.Update()
	//更新二维码地址
	userExtra := model.GetUserExtraByUid(user.Id)
	userExtra.QrPath = ""
	userExtra.Update()
	return nil
}
